<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="解码脚本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pyType">
              <a-input v-model="model.pyType" placeholder="请输入解码脚本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="解码方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventTypes">
              <a-input v-model="model.eventTypes" placeholder="请输入解码方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订阅回调地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventUrl">
              <a-input v-model="model.eventUrl" placeholder="请输入订阅回调地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="indexCode">
              <a-input v-model="model.indexCode" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="同类型报警间隔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventNumber">
              <a-input v-model="model.eventNumber" placeholder="请输入同类型报警间隔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报警消息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventInfo">
              <a-input v-model="model.eventInfo" placeholder="请输入报警消息"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remake">
              <a-input v-model="model.remake" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="推送状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pushStatic">
              <a-input-number v-model="model.pushStatic" placeholder="请输入推送状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="执行状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="runState">
              <a-input-number v-model="model.runState" placeholder="请输入执行状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="播报状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="audioStatic">
              <a-input-number v-model="model.audioStatic" placeholder="请输入播报状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="播报地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="audioId">
              <a-input v-model="model.audioId" placeholder="请输入播报地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否需要前置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isBegin">
              <a-input v-model="model.isBegin" placeholder="请输入是否需要前置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="前置模型类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginEventTypes">
              <a-input v-model="model.beginEventTypes" placeholder="请输入前置模型类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="前置模型内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginName">
              <a-input v-model="model.beginName" placeholder="请输入前置模型内容"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保存目录" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pathSave">
              <a-input v-model="model.pathSave" placeholder="请输入保存目录"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否保存图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="savePic">
              <j-switch v-model="model.savePic"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否开启报警录像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isRecording">
              <j-switch v-model="model.isRecording"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报价录像时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recordTime">
              <a-input-number v-model="model.recordTime" placeholder="请输入报价录像时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否本地保存录像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saveRecord">
              <j-switch v-model="model.saveRecord"  ></j-switch>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TabAiSubscriptionNewForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           pyType: [
              { required: true, message: '请输入解码脚本!'},
           ],
           eventTypes: [
              { required: true, message: '请输入解码方式!'},
           ],
        },
        url: {
          add: "/video/tabAiSubscriptionNew/add",
          edit: "/video/tabAiSubscriptionNew/edit",
          queryById: "/video/tabAiSubscriptionNew/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>